<style lang="less">
  // .main .content-wrapper {
  //   padding: 0;
  //   height: calc(100% - 80px);
  //   overflow: auto;
  // }
  .card_style {
    height: 100%;
    width: 100%;
    overflow: hidden;
    .ivu-card-body {
      padding: 0px;
    }
  }
  .page_style {
    margin-top: 10px;
    text-align: right;
  }
  .bench_search {
    margin-bottom: 10px;
  }
  .nopadding .ivu-table-cell {
    padding: 0px 0px;
  }
  .item1{
    height: 42px;
    line-height: 40px;
  }
  .new-btn-sty {
    margin-right: 5px;
    color: #fff;
    background-color: #235CA7;
    border-color: #235CA7;
    font-weight: 500;
  }
  .new-btn-sty2 {
    margin-right: 20px;
    color: #fff;
    background-color: #ff0101;
    border-color: #ff0000;
    font-weight: 500;
  }
</style>

<template>
  <div>
    <Row class="bench_search">
      <Col span="6">
        <span>社区账号：</span>
        <Input style="width: 70%;" v-model="searchInfo.account" />
      </Col>
      <Button class="new-btn-sty" @click="searchData()"><Icon type="ios-search" /> 搜索</Button>
      <Button class="new-btn-sty2" style="float:right" @click="resetAccount()"><Icon type="ios-refresh" /> 重置账号</Button>
    </Row>
    <div style="margin-top: 20px">
      <Table border :columns="columns1" :data="datalist">
        <template slot-scope="{ row, index }" slot="action">
          <Button type="info" size="small"  @click="goto(row)">跳转</Button>
        </template>
        <template slot-scope="{ row }" slot="action1">
          <Button type="info" size="small"  @click="goto1(row)">跳转</Button>
        </template>
        <template slot-scope="{ row }" slot="action3">
          <Button type="info" size="small"  @click="goto3(row)">跳转</Button>
        </template>
        <template slot-scope="{ row }" slot="action4">
          <Button type="info" size="small"  @click="goto4(row)">跳转</Button>
        </template>
      </Table>
    </div>
    <div style="margin-top: 20px">
      <Table border :columns="columns2" :data="datalist2">
      </Table>
      <Page :total="totpage" style="margin-top: 10px;float:right" @on-change="changePageNo"/>
      <Modal
        v-model="reset.isshow"
        title="提示!!"
        @on-ok="toreset">
        <h1 style="color:red;margin-top: 50px;text-align:center">一经重置，无法恢复，确认重置？</h1>
        <div style="margin-top: 50px;text-align:center;margin-bottom:30px">
          <Row>
            <Col span="12">
              <Input v-model="reset.inscode" placeholder="请输入右侧验证码" style="width: 150px;higt:50px;margin-left:50px" />
            </Col>
            <Col span="6">
              <!-- <div>{{reset.ccode}}</div> -->
              <Button @click="generatedCode">{{reset.ccode}}</Button>
              <!-- <Card style="width:100px;higt:20px" @on-click="generatedCode">
                <div style="text-align:center">
                  {{reset.ccode}}
                </div>
              </Card> -->
            </Col>
          </Row>
        </div>
    </Modal>
    </div>
    <Modal v-model="modal1" title="填写手机号码" width="500" cancel-text="关闭"
      @on-ok="ok(paramData)" @on-cancel="modal1 = false" ok-text="确定" style="position:relative;">
      <Form ref="paramData" :model="paramData"  >
        <Row class="item1">
          <Col span="6" style="text-align: center" class="">手机号码:</Col>
          <Col span="12">
            <Input v-model="paramData.mobile" placeholder=""></Input>
          </Col>
        </Row>
      </Form>
    </Modal>
    <Modal v-model="modal2" title="填写登录密码" width="500" cancel-text="关闭"
      @on-ok="ok11(paramData2)" @on-cancel="modal2 = false" ok-text="确定" style="position:relative;">
      <Form ref="paramData" :model="paramData2"  >
        <Row class="item1">
          <Col span="6" style="text-align: center" class="">登录密码:</Col>
          <Col span="12">
            <Input v-model="paramData2.password" placeholder=""></Input>
          </Col>
        </Row>
      </Form>
    </Modal>
  </div>
</template>
<script>
import { getAccountInfoForKF, getAccountPassForKF, userLoginMZ } from '@/api/customer-service'
import { getUserInfoByLoginName, updateResetAccount } from '@/api/common'
export default {
  name: 'communityinfo',
  data () {
    return {
      modal: false,
      modal1: false,
      modal2: false,
      totpage: 0,
      pagesize: 10,
      pageno: 1,
      searchInfo: {
        account: ''
      },
      paramData: {
        mobile: ''
      },
      paramData2: {
        password: ''
      },
      columns1: [
        { title: '序号', type: 'index', width: 70, align: 'center' },
        { title: '社区名称', key: 'company_name', width: 250, align: 'center' },
        { title: '社区账号', key: 'company_code', width: 100, align: 'center' },
        { title: '高拍仪', key: 'email', width: 130, align: 'center' },
        { title: '人设免密登录', slot: 'action', width: 120, align: 'center' },
        { title: '医保免密登录', slot: 'action1', width: 120, align: 'center' },
        { title: '特困免密登录', slot: 'action3', width: 120, align: 'center' },
        { title: '房产免密登录', slot: 'action4', width: 120, align: 'center' },
        {
          title: '操作',
          key: 'action4',
          align: 'center',
          className: 'nopadding',
          minWidth: 200,
          render: (h, params) => {
            let company_code = this.$store.state.user.severUserInfo.company_code
            console.log(company_code)
            let abc = [h('Button', {
              props: {
                type: 'primary',
                size: 'small'
              },
              style: {
                marginRight: '5px',
                backgroundColor: '#598ED1 ',
                borderColor: '#598ED1'
              },
              on: {
                click: () => {
                  this.getPassword(params.row)
                }
              }
            }, '获取登录密码'),
            h('Button', {
              props: {
                type: 'primary',
                size: 'small'
              },
              style: {
                marginRight: '5px',
                backgroundColor: '#598ED1 ',
                borderColor: '#598ED1'
              },
              on: {
                click: () => {
                  this.loginCommunity(params.row)
                }
              }
            }, '登录')]
            return h('div', abc)
          }
        }
      ],
      columns2: [
        { title: '社区名称', key: 'company_name', width: 120, align: 'center' },
        { title: '社区账号', key: 'login_code', width: 120, align: 'center' },
        { title: '登录账号', key: 'login_name', width: 120, align: 'center' },
        { title: '登录密码', key: 'password', width: 130, align: 'center' },
        { title: '登录系统', key: 'login_system_name', width: 120, align: 'center' },
        { title: '信息', key: 'result', width: 200, align: 'center' },
        { title: '登录时间', key: 'create_time', width: 220, align: 'center' },
        { title: '浏览器', key: 'browser', width: 120, align: 'center' }
      ],
      datalist: [],
      datalist2: [],
      company_map: {},
      reset: {
        ccode: '',
        isshow: false,
        inscode: ''
      }
    }
  },
  computed: {
    companyCode () {
      return this.$store.state.user.severUserInfo.company_code
    }
  },
  methods: {
    changePageNo (pageNo) {
      this.pageno = pageNo
      searchData()
    },
    resetAccount () {
      this.generatedCode()
      this.reset.isshow = true
    },
    searchData (index) { // 根据账号搜索功能
      this.datalist = []
      this.datalist2 = []
      let params = {
        account: this.searchInfo.account,
        pageSize: this.pagesize,
        pageNo: this.pageno
      }
      getAccountInfoForKF(params).then(res => {
        console.log(res.data.data)
        if (res.data.errcode === 0) {
          var obj = {}
          if (res.data.data.renSheWuMiInfo) {
            obj['rsurl'] = res.data.data.renSheWuMiInfo.url
          }
          if (res.data.data.yiBaoWuMiINfo) {
            obj['yburl'] = res.data.data.yiBaoWuMiINfo.url
          }
          if (res.data.data.teKunWuMiInfo) {
            obj['tkurl'] = res.data.data.teKunWuMiInfo.url
          }
          if (res.data.data.fangChanZuLinWuMiInfo) {
            obj['request_url'] = res.data.data.fangChanZuLinWuMiInfo.request_url
            obj['browse_url'] = res.data.data.fangChanZuLinWuMiInfo.browse_url
          }
          var d = Object.assign({}, obj, res.data.data.company_map)
          console.log(d, 'd')
          this.datalist.push(d)
          this.datalist2 = res.data.data.page.results
          this.totpage = res.data.data.page.totalRecord
          this.company_map = res.data.data.company_map
        } else {
          this.$Notice.error({
            title: '获取社区信息失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    goto (item) {
      if (item.rsurl) {
        window.open(item.rsurl)
      } else {
        this.$Notice.error({
          title: '人设免密登录失败',
          desc: '人设免密登录失败'
        })
      }
    },
    goto1 (item) {
      if (item.yburl) {
        window.open(item.yburl)
      } else {
        this.$Notice.error({
          title: '医保免密登录失败',
          desc: '医保免密登录失败'
        })
      }
    },
    goto3 (item) {
      if (item.tkurl) {
        window.open(item.tkurl)
      } else {
        this.$Notice.error({
          title: '特困免密登录失败',
          desc: '特困免密登录失败'
        })
      }
    },
    goto4 (item) {
      if (item.request_url && item.browse_url) {
        const { href } = this.$router.resolve({
          path: '/newhouserent',
          query: {
            request_url: item.request_url,
            browse_url: item.browse_url
          }
        })
        window.open(href, '_blank')
      } else {
        this.$Notice.error({
          title: '房产免密登录失败',
          desc: '房产免密登录失败'
        })
      }
    },
    getPassword () {
      this.paramData = {}
      this.modal1 = true
    },
    ok () {
      if (this.paramData.mobile === '' || this.paramData.mobile === undefined) {
        const content = '<p>请填写手机号码</p>'
        this.$Modal.error({
          title: '手机号码不能为空',
          content: content
        })
        return
      }
      getAccountPassForKF(this.searchInfo.account, this.paramData.mobile).then(res => {
        console.log(res.data.data)
        if (res.data.errcode === 0) {
          console.log('成功')
        } else {
          this.$Notice.error({
            title: '获取登录密码失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    loginCommunity () {
      this.paramData2 = {}
      this.modal2 = true
    },
    ok11 () {
      // if (this.paramData.password === '' || this.paramData.password === undefined) {
      //   const content = '<p>请填写登录密码</p>'
      //   this.$Modal.error({
      //     title: '登录密码不能为空',
      //     content: content
      //   })
      //   return
      // }
      let param = {
        password: this.paramData2.password,
        username: this.searchInfo.account
      }
      userLoginMZ(param).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success('登录成功')
          this.$router.push({
            name: 'mainv3'
          })
          location.reload()
          // window.open('http://qstb.mzj.shenyang.gov.cn/#/mainv3')
        } else {
          this.$Message.error(res.data.errmsg)
        }
      })
    },
    generatedCode () {
      const random = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
        'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
        't', 'u', 'v', 'w', 'x', 'y', 'z']
      let code = ''
      for (let i = 0; i < 6; i++) {
        let index = Math.floor(Math.random() * 62)
        code += random[index]
      }
      this.reset.ccode = code
      console.log('------', code)
    },
    toreset () {
      if (this.reset.ccode === this.reset.inscode) {
        if (!this.company_map.login_name) {
          this.$Message.error('无账号信息！')
          return
        }
        var param = {
          loginName: this.company_map.login_name
        }
        getUserInfoByLoginName(param).then(res => {
          console.log(res.data.data)
          if (res.data.errcode === 0) {
            var param1 = {
              id: res.data.data.id
            }
            updateResetAccount(param1).then(res1 => {
              if (res1.data.errcode === 0) {
                this.$Notice.success({ title: '重置成功' })
              } else {
                this.$Message.error('重置失败！')
              }
            })
          } else {
            this.$Notice.error({ title: res.data.errmsg })
          }
        })
      } else {
        this.$Message.error('验证码错误，无法重置！')
      }
    }
  },
  mounted () {
    console.log(this.companyCode, 'companyCodecompanyCode')
  }
}
</script>
